package app;

public class Car {

	private String registrationNumber;
	private Name driverName;
	
	public Car(String registrationNumber, Name driverName) throws RegistrationFormatException, DriverNameException {
	   
	    	this.registrationNumber = registrationNumber;
		    this.driverName = driverName;
		    //if (registrationNumber.matches(("//// &$%"))) {
            	//throw new IllegalStateException("No non-letter in "
            	//	+ "car registration number");
          // 	}
		    if( registrationNumber.trim().length() != 8 ){
	           	throw new RegistrationFormatException(registrationNumber);
	        }
	        
	        else if (driverName.getFullName().trim().length() == 0){
	        	throw new DriverNameException(driverName.getFullName());
	       	}
	} // END OF CONSTRUCTOR

	
	

    public String getRegistrationNumber() {
		return registrationNumber;
	}

	public void setRegistrationNumber(String registrationNumber) {
		this.registrationNumber = registrationNumber;
	}

	public Name getDriverName() {
		return driverName;
	}

	public void setDriverName(Name driverName) {
		this.driverName = driverName;
	}
	
	public boolean equals(Object other) {
		if(other instanceof Car) {
			Car otherCar = (Car) other;
			if(registrationNumber.equals(otherCar.registrationNumber))
			return true;
		}
		return false;	
	}
	
	public int hashCode() {
		return registrationNumber.hashCode();
	}
}
